export enum LevelResult {
  pending,
  pass,
  moreThings,
  fail,
}

export enum QuestionButton {
  ask,
  confirm,
  redirect
}

export class Game {
  static readonly levelCount = 3;
  private static readonly treasureMessages = [
    "获得奖励（奖品在钢琴的红布下方）",
    "获得奖励（请打开冰箱最下面的门）",
    "请再接再励",
  ];
  static readonly questions = [
    {
      msg: "请咨询你旁边的人",
      buttons: [
        QuestionButton.ask
      ]
    },
    {
      msg: "选择问号会导致你不能到达终点，也获取不了钥匙和宝箱，请问你是否重新开始",
      buttons: [
        QuestionButton.confirm,
        QuestionButton.redirect
      ]
    },
    {
      msg: `你经常问我能不能一生一世
我都会回答长长久久便好
但答案或许是与你才能一直长久
而非我独自久等`,
      buttons: [
        QuestionButton.ask
      ]
    },
  ];

  level = 0;
  levelResult = LevelResult.pending;

  getTreasureMessage() {
    return Game.treasureMessages[this.level - 1];
  }

  getPassMessage() {
    return this.hasNext()
      ? `恭喜过第${this.level}关！快找你身边的人索要礼物吧！`
      : "千里迢迢，万里涛涛。执子的手，与子一起老。 --编者注";
  }

  getMoreThingsMessage() {
    return `恭喜过第${this.level}关，地图上仍存在道具`;
  }

  getFailMessage() {
    return '体力用尽';
  }

  getMessage() {
    let msg = ''
    switch (this.levelResult) {
      case LevelResult.pending:
        break
      case LevelResult.pass:
        msg = this.getPassMessage()
        break
      case LevelResult.moreThings:
        msg = this.getMoreThingsMessage()
        break
      case LevelResult.fail:
        msg = this.getFailMessage()
        break
    }
    return msg
  }

  getQuestion() {
    return Game.questions[this.level - 1]
  }

  pass() {
    this.levelResult = LevelResult.pass;
  }

  moreThings() {
    this.levelResult = LevelResult.moreThings;
  }

  fail() {
    this.levelResult = LevelResult.fail;
  }

  next() {
    this.levelResult = LevelResult.pending;
    this.level++;
  }

  restart() {
    this.levelResult = LevelResult.pending;
  }

  hasNext() {
    return this.level < Game.levelCount;
  }
}
